package com.shengyin.ec.model.dao.alliance;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.AllianceViewerInfo;
import com.shengyin.ec.model.entity.Company;

@Repository("allianceViewerInfoDao")
public class AllianceViewerInfoDaoImpl extends BaseDaoImpl<AllianceViewerInfo> implements AllianceViewerInfoDao {
	
	public AllianceViewerInfo getAllianceViewerByAllianceViewerId(long id){
		List<AllianceViewerInfo> allianceViewList =  super.find("from AllianceViewerInfo where id='"+id+"'");
		return allianceViewList.get(0);
	}
	
	public List<AllianceViewerInfo> getAllianceViewerListByAllianceCompanyId(long companyId){
		List<AllianceViewerInfo> allianceViewList =  super.find("from AllianceViewerInfo where companyId='"+companyId+"'");
		return allianceViewList;
	}
	
	public void addAllianceViewerByAllianceViewerId(AllianceViewerInfo allianceViewerInfo){
		
	}
	
	public boolean checkAllianceViewer(String username, String password){
		try {
			ArrayList<AllianceViewerInfo> list = (ArrayList<AllianceViewerInfo>) super.find("From AllianceViewerInfo c where c.viewName='"+username+"' and c.viewPsw='"+password+"'");
			if(list.size()==0)
			   return false;
			else
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public int getAllianceViewType(String username){
		ArrayList<AllianceViewerInfo> list = (ArrayList<AllianceViewerInfo>) super.find("From AllianceViewerInfo c where c.viewName='"+username+"'");
		return list.get(0).getStatus();
	}
	
	public AllianceViewerInfo getAllianceViewerByName(String name){
		List<AllianceViewerInfo> list = (ArrayList<AllianceViewerInfo>)super.find("From AllianceViewerInfo c where c.viewName='"+name+"'");
		return list.get(0);
	}
}